﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CoyoEden.Uploader;
using CoyoEden;
using CoyoEden.Web.Controls;

public partial class admin_Pages_Upload : AdminBasePage
{
	#region member variables
	private string _Uploader;
	/// <summary>
	/// Uploader
	/// </summary>
	public string Uploader {
		get {
			if(string.IsNullOrEmpty(_Uploader)){	
				return "SWF";
			}//Default uploader is SWFUpload
			return _Uploader;
		}
		set {
			_Uploader = value;
		}
	}
	private string _Relation;
	/// <summary>
	/// Upload relationship.Category/Post/Page/None,etc.
	/// </summary>
	public string Relation {
		get {
			if (string.IsNullOrEmpty(_Relation)) {
				return "none";
			}
			return _Relation;
		}
		set { _Relation = value; }
	}
	/// <summary>
	/// Relation obj's value
	/// </summary>
	public string RelationValue { get; set; }
	/// <summary>
	/// File number limit per upload.
	/// </summary>
	public int Limit { get; set; }
	/// <summary>
	/// SWFUploadUrl.Readonly
	/// </summary>
	public string SWFUploadUrl {
		get {
			return Utils.AbsoluteWebRoot + "SWFUpload.axd";
		}
	}
	/// <summary>
	/// Whether upload an image."1" yes,"0" v.v.
	/// </summary>
	public string IsImage { get; set; }
	#endregion
	protected void Page_Load(object sender, EventArgs e)
	{
		//Which upload control we use
		_Uploader = Request["uploader"];
		_Relation = Request["rel"];
		RelationValue=Request["relval"];
		IsImage = Request["isImg"];
		Limit = string.IsNullOrEmpty(Request["limit"]) ? 0 : Convert.ToInt16(Request["limit"]);

		switch (Uploader) { 
			case "SWF":
				this.phSWFUpload.Visible = true;
				break;
			case "DJUPLOAD":
				this.phAspNetFileUpload.Visible = true;
				InitDJUpload();
				break;

		};

	}

	#region helper methods
	private void InitDJUpload() {
		if (!Page.IsCallback)
		{
			Utils.AddJavaScriptInclude(Utils.RelativeWebRoot + "assets/js/jquery/jquery.js", Page, true);
			Utils.AddJavaScriptInclude(Utils.RelativeWebRoot + "assets/js/jquery/jquery.ui.all.min.js", Page, true);
			Utils.AddJavaScriptInclude(Utils.RelativeWebRoot + "assets/js/plugins/jquery.json.js", Page, true);
		}
		FileSystemProcessor fsp = new FileSystemProcessor();
		fsp.OutputPath += "App_Data/files";
		this.DJUploadController1.DefaultFileProcessor = fsp;
	}
	#endregion
}
